package com.xinlong.dao;

import com.xinlong.entity.Member;
import com.xinlong.entity.Orders;
import com.xinlong.entity.product;
import org.apache.ibatis.annotations.*;
import java.util.Map;

import java.util.List;

public interface OrdersDao {

    @Select("select * from orders where orderStatus in (#{orderStatus})")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "orderNum", property = "orderNum"),
            @Result(column = "orderTime", property = "orderTime"),
            @Result(column = "orderStatus", property = "orderStatus"),
            @Result(column = "peopleCount", property = "peopleCount"),
            @Result(column = "payType", property = "payType"),
            @Result(column = "orderDesc", property = "orderDesc"),
            @Result(column = "memberId",property = "member",javaType = Member.class,one = @One(select = "com.xinlong.dao.Imemberdao.findByid")),
            @Result(column = "productId", property = "product", one = @One(select = "com.xinlong.dao.Iproductdao.findById"))

    })
    List<Orders> findAll(@Param("orderNum") String orderNum,@Param("orderStatus") String orderStatus) throws Exception;

    @Select("select * from orders where id=#{id}")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "orderNum", property = "orderNum"),
            @Result(column = "orderTime", property = "orderTime"),
            @Result(column = "orderStatus", property = "orderStatus"),
            @Result(column = "peopleCount", property = "peopleCount"),
            @Result(column = "payType", property = "payType"),
            @Result(column = "orderDesc", property = "orderDesc"),
            @Result(column = "productId", property = "product",javaType = product.class, one = @One(select = "com.xinlong.dao.Iproductdao.findById")),
            @Result(column = "memberid",property = "member",javaType = Member.class,one = @One(select = "com.xinlong.dao.Imemberdao.findByid")),
            @Result(column = "id",property = "travellers",javaType = List.class,many = @Many(select = "com.xinlong.dao.TravellerMapper.findByordersid"))
    })
    Orders findbyid(String id);


    /**
     * 根据订单号查询
     * @param orderNum
     * @return
     */
    List<Orders> selByCondition(@Param("orderNum")String orderNum,@Param("orderStatus") String orderStatus);

    /**
     * 添加订单
     * @param orders
     * @return
     */
    int insOrder(Orders orders);


    /**
     * 修改订单信息
     * @param orders
     * @return
     */
    int update(Orders orders);

    /**
     * 根据年份统计
     * @return
     */
    List<Map<String,Object>> year();

    /**
     * 根据月份统计
     * @return
     */
    List<Map<String,Object>> month();

    /**
     * 热门城市
     * @return
     */
    List<Map<String,Object>> popular();

    /**
     * 修改状态为进行中
     * @return
     */
    Integer updateStatus2();

    /**
     * 修改状态为已完成
     * @return
     */
    Integer updateStatus3();
}
